/**
 * Copyright (C), 2020, 安徽贝慕信息科技有限公司
 * FileName: DealerUserController
 * Author:   Allen
 * Date:     2020/8/27 15:22
 * Description: 商家用户信息登记业务处理Controller
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.bim.marvel.rest;

import com.bim.marvel.openapi.client.dto.DealerUserDTO;
import com.bim.marvel.common.core.model.dto.SimpleVO;
import com.bim.marvel.openapi.client.query.DealerUserQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.Valid;

/**
 * 〈商家用户信息登记业务处理Controller〉
 *
 * @author Allen
 * @date 2020/8/27
 * @since 1.0.0
 */
@Api(tags = {"商家用户注册业务处理-controller"})
@RequestMapping("/api/dealer/user")
public interface DealerUserController {

    /**
     * 判断此登录名是否已存在的请求URL
     */
    String EXIST_LOGIN_NAME_URL = "/exist";

    /**
     * 判断此手机号是否已存在的请求URL
     */
    String EXIST_PHONE_URL = "/exist/phone";

    /**
     * 保存用户实体信息请求URL
     */
    String DEALER_USER_SAVE_URL = "/save";

    /**
     * 根据ID查询用户信息url
     */
    String GET_USER_INFO_BY_ID = "/userInfo";
    /**
     * 保存用户实体信息
     * @param dealerUserQuery 用户实体信息入参
     * @return 保存状态
     */
    @ApiOperation(value = "保存用户实体信息", notes = "保存用户实体信息",
            protocols = "http,https", httpMethod = "POST")
    @PostMapping(value = DEALER_USER_SAVE_URL, consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE},
            produces = {MediaType.APPLICATION_JSON_VALUE})
    SimpleVO<Boolean> saveDealerUser(@Valid DealerUserQuery dealerUserQuery);

    /**
     * 根据id查询用户信息(包括岗位等多表的综合查询信息) 因此处支持手机号码登陆，故而这里的loginName可能会是手机号
     * <p>
     * 由于token中的user_name定义为字符串， 故而此处引用@AuthenticationPrincipal类时请求的参数也应为字符型，否则无法解析
     * </p>
     *
     * @param loginName 用户id
     * @return 用户数据
     */
    @ApiOperation(value = "根据用户登录账号查询用户信息", notes = "查询用户信息",
            protocols = "http,https", httpMethod = "GET")
    @GetMapping(value = GET_USER_INFO_BY_ID, produces = {MediaType.APPLICATION_JSON_VALUE})
    SimpleVO<DealerUserDTO> getDealerUserInfo(@ApiParam(name = "loginName", value = "用户编码", hidden = true)
                                                      String loginName);

    /**
     * 判断登录名是否存在
     * @param loginName 登录名
     * @return 是否存在
     */
    @ApiOperation(value = "判断登录名是否存在", notes = "判断登录名是否存在",
            protocols = "http,https", httpMethod = "GET")
    @GetMapping(value = EXIST_LOGIN_NAME_URL, produces = {MediaType.APPLICATION_JSON_VALUE})
    SimpleVO<Boolean> getLoginNameExist(@ApiParam(name = "loginName", value = "用户编码")
                                        @RequestParam("loginName") String loginName);

    /**
     * 判断手机号是否存在
     * @param phone 手机号
     * @return 是否存在
     */
    @ApiOperation(value = "判断手机号是否存在", notes = "判断手机号是否存在",
            protocols = "http,https", httpMethod = "GET")
    @GetMapping(value = EXIST_PHONE_URL, produces = {MediaType.APPLICATION_JSON_VALUE})
    SimpleVO<Boolean> getPhoneExist(@ApiParam(name = "phone", value = "手机号")
                                    @RequestParam("phone")  String phone);
}
